﻿@{
    ViewData["Title"] = "Index";
    Layout = "~/Areas/Console/Views/Shared/_Layout.cshtml";
}
@section head{
    <script type="text/javascript">
        var renderTable;
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'table', 'form'], function () {
            var $ = layui.$
                , form = layui.form
                , admin = layui.admin
                , table = layui.table;

            var columns = [];

            if ('@ViewBag.type' == "rebateLevel") {
                columns = [
                    { field: 'index', title: '序号', type: 'numbers', width: 60, templet: '#zizeng' }
                    , { field: 'names', title: '名称' }
                    , { field: 'levelSort', title: '等级' }
                    , { field: 'sort', title: '排序' }
                    , { field: 'remark', title: '备注' }
                    , { field: 'creator', title: '创建人' }
                    , { field: 'createDate', title: '添加时间', width: 160 }
                    , { field: 'operate', fixed: 'right', title: '操作', width: 220, toolbar: '#table-datalist-bar' }
                ];
            } else {
                columns = [
                    { field: 'index', title: '序号', type: 'numbers', width: 60, templet: '#zizeng' }
                    , { field: 'names', title: '名称' }
                    , { field: 'sort', title: '排序' }
                    , { field: 'remark', title: '备注' }
                    , { field: 'creator', title: '创建人' }
                    , { field: 'createDate', title: '添加时间', width: 160 }
                    , { field: 'operate', fixed: 'right', title: '操作', width: 220, toolbar: '#table-datalist-bar' }
                ];
            }

            renderTable = function () {
                table.render({
                    elem: '#table-datalist'
                    , url: '/Console/Codes/GetListJson'
                    , toolbar: '#table-datalist-toolbar'
                    , where: { type : '@ViewBag.type' }
                    , limit: 20
                    , cols: [columns]
                    , page: { layout: ['prev', 'page', 'next', 'refresh'] }
                    , done: function (res) {
                        if (res.count == 0) {
                            $(".layui-table-main").html('<div class="layui-none">' + top.lang.noData + '</div>');
                        }
                        layer.closeAll('loading');
                        /**多语言初始化 */
                        top.SetListPageLanguage(layui);
                    }
                });
            };
            renderTable();

            //头工具栏事件
            table.on('toolbar(table-datalist)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                var data = checkStatus.data;
                switch (obj.event) {
                    case 'addNew':
                        top.OpenPageByKey(layui, "addNew", 2, '800px', '650px', '/Console/Codes/Create?type=@ViewBag.type');
                        break;
                    case 'Return':
                        window.location.href = "/Console/Codetypes/Index";
                        break;
                };
            });

            //监听行工具事件
            table.on('tool(table-datalist)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    var postData = {
                        id: data.id
                    };
                    top.ConfirmByKey(layui, 'confirmDelete', postData, "/Console/Codes/Delete", "POST", "deleteSuccess", "deleteFail", function () {
                        renderTable();
                    });
                } else if (obj.event === 'edit') {
                    top.OpenPageByKey(layui, "edit", 2, '800px', '650px', '/Console/Codes/Edit?id=' + data.id);
                }
            });

        });
    </script>
}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <table class="layui-hide" id="table-datalist" lay-filter="table-datalist"></table>
                    <script type="text/html" id="zizeng">
                        {{d.LAY_TABLE_INDEX+1}}
                    </script>
                    <script type="text/html" id="table-datalist-toolbar">
                        <div class="layui-btn-container">
                            <button class="layui-btn layui-btn-sm" lay-event="addNew">新增</button>
                            <button class="layui-btn layui-btn-sm" lay-event="Return">返回</button>
                        </div>
                    </script>
                    <script type="text/html" id="table-datalist-bar">
                        <button class="layui-btn layui-btn-sm" lay-event="edit">编辑</button>
                        <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</button>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>